<?php
	include_once 'isLogin.php';
	$reset=$commonc->getInfo('admin',$_COOKIE['admin_id']);
	$table_name='company_product';
	if($_GET['id']!=false){
			$old = $commonc->getInfo($table_name,$_GET['id'],'img');
			$img = $old['img'];
		}
	//上传商品图片img_0，生成缩略图
		if($_FILES['img_0']['name']!=''){
			//设置路径
			$folder="upload/product/";
			$annexFolder = $folder;
			//删除旧图
			@unlink($annexFolder.$img);
			//上传新图
			$upimg = new uploadImg();
			$img_0= $upimg->upLoad('img_0',$annexFolder);
		}
		//获取营业执照
		if($_GET['id']!=false){
			$olds = $commonc->getInfo($table_name,$_GET['id'],'img_1');
			$img_1 = $olds['img_1'];
		}
		//上传商品图片img_1，生成缩略图
		if($_FILES['img_1']['name']!=''){
			//设置路径
			//$folder= $GLOBALS['common']['imgPath']."upload/image/";
			$folder="upload/product/";
			$annexFolder = $folder;
			//删除旧图
			@unlink($annexFolder.$img_1);
			//上传新图
			$upimg = new uploadImg();
			$img_1 = $upimg->upLoad('img_1',$annexFolder);
		}
		//获取img_2图片
		if($_GET['id']!=false){
			$old = $commonc->getInfo($table_name,$_GET['id'],'img_2');
			$img_2 = $old['img_2'];
		}
		
		//上传图片img_2，生成缩略图
		if($_FILES['img_2']['name']!=''){
			//设置路径
			$folder="upload/product/";
			$annexFolder = $folder;
			//删除旧图
			@unlink($annexFolder.$img);
			//上传新图
			$upimg = new uploadImg();
			$img_2 = $upimg->upLoad('img_2',$annexFolder);
		}
	//将数据插入数据库
	 $data = array('company_id'=>$reset['company_id'],'name'=>$_POST['name'],'price'=>$_POST['price'],'time_imit'=>$_POST['time_imit'],'detail_description'=>$_POST['detail_description'],'img_0'=>$img_0,'img_1'=>$img_1,'img_2'=>$img_2);
	 if($_POST['submit']=='发布'){
		if($_GET['id']!=false){
			$commonc->update($table_name,$data,"id='".$_GET['id']."'");
			$href = $_basename.'?id='.$_GET['id'];
		}else{
				$commonc->insert($table_name,$data);
				$href='product_list.php';
				$id = $commonc->insert_id();
				$data = array('sort'=>$id);
				$commonc->update($table_name, $data, "id='".$id."'");
			
			}
		echo $commonc->submitAlert('成功',$href);
	
	 }
	
	//获取数据
	$result= $commonc->getInfo($table_name,$_GET['id']);
	$smarty->assign('row',$result);
	
	$smarty->display($_filename.".html");
	
?>